from api.base_api import BaseApi
from common.read_json import read_json
import unittest
from parameterized import parameterized
from common.assert_common import assert_common
from common.html_util import html_util
from common.dbuilt import init_tender_info

class TestTenderApi(unittest.TestCase):
    def setUp(self) -> None:
        self.tender_api = BaseApi()
        init_tender_info()

    def tearDown(self) -> None:
        self.tender_api.session.close()

    @parameterized.expand(read_json('tender','tenderapi'))
    def test01_tender(self,keywords,amount,exp_status_code,exp_status,exp_description):
        self.tender_api.reg_login_mode().user_login(keywords, "l123456")
        response = self.tender_api.tender_mode().tender(amount)
        assert_common(self,response,exp_status_code,exp_status,exp_description)

    def test02_third_tender(self):
        self.tender_api.reg_login_mode().user_login("15878945622", "l123456")
        ten_response = self.tender_api.tender_mode().tender(1000)
        url = html_util(ten_response)[0]
        form_data = html_util(ten_response)[1]
        response = self.tender_api.tender_mode().third_tender(url,form_data)
        self.assertEqual(200,response.status_code)
        self.assertIn('OK',response.text)
